package com.example.controller;

import com.example.common.Result;
import com.example.service.TraceFromSourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collections;
import java.util.List;

@RestController
@Slf4j
@CrossOrigin
public class TraceFromSourceController {
    @Autowired
    private TraceFromSourceService traceFromSourceService;

    /**
     * 上传文件，溯源该文件
     * @param file 文件
     * @return
     * @throws Exception
     */
    @PostMapping("/traceFromSource")
    public Result traceFromSource(@RequestParam("file")MultipartFile file) throws Exception {

        //调用service层获取路径
        List<String> path = traceFromSourceService.traceFromSource(file);
        //反转列表，形成从源头到当前的 一条路径
        Collections.reverse(path);
        return Result.success(path);
    }
}
